<template>
  <div>
    <div class="add-container">
      <div class="add-title">
        <h1>添加收货地址</h1>
      </div>
      <div class="add-box">
        <Form :model="addForm" label-position="left" :label-width="100" >
          <FormItem label="收件人" prop="name">
            <i-input v-model="addForm.recename" size="large"></i-input>
          </FormItem>
          <FormItem label="收件地址" prop="address">
            <i-input v-model="addForm.address" size="large"></i-input>
          </FormItem>
          <FormItem label="手机号码" prop="phone">
            <i-input v-model="addForm.mobile" size="large"></i-input>
          </FormItem>
        </Form>
      </div>
      <div class="add-submit">
        <Button type="primary" @click="confirmAdd">确认添加</Button>
      </div>
    </div>
  </div>
</template>

<script>
import Distpicker from 'v-distpicker';
export default {
  name: 'AddAddress',
  data () {
    return {
      addForm: {
        recename: '',
        address: '',
        mobile: '',
        userid:window.sessionStorage.userid
      },
      ruleInline: {
        name: [
          { required: true, message: '请输入姓名', trigger: 'blur' }
        ],
        address: [
          { required: true, message: '请输入地址', trigger: 'blur' }
        ],
        postalcode: [
          { required: true, message: '请输入邮政编码', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '手机号不能为空', trigger: 'blur' },
          { type: 'string', pattern: /^1[3|4|5|7|8][0-9]{9}$/, message: '手机号格式出错', trigger: 'blur' }
        ]
      }
    };
  },
  methods: {
     async confirmAdd(){
         const {data:res}=await this.$axios.post("http://localhost:8080/api/shopmall/address/add",{
           params:this.addForm
         })
        //  console.log(res)
        if(res.code!==200) return this.$message.error('添加地址失败')
        this.$message.success('添加地址成功')
        // this.addForm=''
         this.$router.push({ path: "myAddress" })
     }
  },
  components: {
    Distpicker
  }
};
</script>

<style scoped>
.add-container {
  margin: 15px auto;
  width: 60%;
  min-width: 600px;
}
.add-title {
  margin-bottom: 15px;
  text-align: center;
}
.add-submit {
  display: flex;
  justify-content: center;
}
</style>
